#include<vector>
#include<memory>
using namespace std;
class Iterator {
public:
	virtual int first()=0;
	virtual bool hasNext()=0;
	virtual int next()=0;
};

class ConcreteIterator:public Iterator {
private:
	vector<int>* data;
	int index = 0;
public:
	ConcreteIterator(vector<int>* data):data(data){}
	int first() {
		index = 0;
		return data->at(index);
	}
	bool hasNext() {
		return index < data->size();
	}
	int next() {
		return data->at(index);
	}
};

class Aggregate {
public:
	virtual void add(int val) = 0;
	virtual void remove(int val) = 0;
	virtual shared_ptr<Iterator> getIterator() = 0;
};

class ConcreteAggregate:public Aggregate {
private:
	vector<int>data;
public:
	void add(int val) {
		data.push_back(val);
	}

	void remove(int val) {
		auto it = data.begin();
		while(it!=data.end()){
			if (*it == val) {
				data.erase(it);
				break;
			}
			++it;
		}
	}

	shared_ptr<Iterator> getIterator() {
		return shared_ptr<Iterator>(new ConcreteIterator(&data));
	}
};